package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.*;
import com.itheima.health.service.MemberService;
import com.itheima.health.service.OrderService;
import com.itheima.health.service.SetMealService;
import com.itheima.health.vo.OrderSubmitParam;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/mobile/order")
//http://localhost:9002/mobile/setmeal/getSetmeal
public class MobileSetmealcontroller {

    @Autowired
    private SetMealService setMealService;
    @Autowired
    private MemberService memberService;
    @Autowired
    private OrderService orderService;




    /**
     * 提交订单
     */

    @RequestMapping("/submit")
    public Result submit(@RequestBody OrderSubmitParam param) {
        log.info("[提交预约信息]data：{}", param);


        //2-创建会员 memberService
        Member member = new Member();
        member.setIdCard(param.getIdCard());
        member.setPhoneNumber(param.getTelephone());
        member.setName(param.getName());
        member.setSex(param.getSex());
        member = memberService.createOrUpdate(member);

        //3-提交体检信息  orderService
        Order order = new Order();
        order.setOrderStatus(Order.ORDERSTATUS_NO);
        order.setSetmealId(param.getSetMealId());
        order.setOrderType(Order.ORDERTYPE_WEIXIN);
        order.setOrderDate(param.getOrderDate());
        order.setMemberId(member.getId());
        order = orderService.add(order);

        //4-返回结果
        return new Result(true, MessageConst.ORDER_SUCCESS,order);
    }

    /**
     * 预约详情
     */
    @GetMapping("findById")
    public Result select(@RequestParam Integer id) {
        log.info("预约订单的id：{}", id);
        OrderNewDto orderById = setMealService.findById(id);
        return new Result(true, "展示成功",orderById);
    }

}
